package com.ruoyi.web.controller.common;

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoInfoRequest;

import java.util.List;

import static com.ruoyi.web.controller.common.GetVideoTest.getPlayInfo;
import static com.ruoyi.web.controller.common.Video.initVodClient;

/**
 * @author 伟峰
 * @date 2022/5/14
 * @description:
 */
public class UploadVideo {

    //账号AK信息请填写(必选)
    private static final String accessKeyId = "xxxxxxxx";
    //账号AK信息请填写(必选)
    private static final String accessKeySecret = "xxxxxxx";

    private static final String title="视频点播上传"; //标题
    private static final String fileName="D:\\QLDownload\\短腿小柯基：猫咪铲屎官的责任 270P(流畅).mp4";

//    public static void main(String[] args) throws ClientException {
//
//            UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
//            /* 可指定分片上传时每个分片的大小，默认为2M字节 */
//            request.setPartSize(2 * 1024 * 1024L);
//            /* 可指定分片上传时的并发线程数，默认为1，(注：该配置会占用服务器CPU资源，需根据服务器情况指定）*/
//            request.setTaskNum(1);
//
//            UploadVideoImpl uploader = new UploadVideoImpl();
//            UploadVideoResponse response = uploader.uploadVideo(request);
//
//            if (response.isSuccess()) {
//                System.out.print("VideoId=" + response.getVideoId() + "\n");
//            } else {
//                /* 如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因 */
//                System.out.print("VideoId=" + response.getVideoId() + "\n");
//                System.out.print("ErrorCode=" + response.getCode() + "\n");
//                System.out.print("ErrorMessage=" + response.getMessage() + "\n");
//            }
//
//    }


    public static void main(String[] args) throws ClientException {
        getVideoUrl();
    }

    public static void getVideoUrl() throws ClientException {
        DefaultAcsClient client = initVodClient("xxxx", "xxxxx");
        GetPlayInfoResponse response = new GetPlayInfoResponse();
        try {

            response =getPlayInfo(client);
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            }
            //Base信息
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }




    /*获取播放地址函数*/
    public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        request.setVideoId("xxxx");
        request.setVideoId("xxxx");

        return client.getAcsResponse(request);
    }







}
